﻿
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');

FantastPlatform.UI.EmergencyFlow = function (config) {
    Ext.apply(this, config);
    var newWidth = 1024;
    var newHeight = 570;
    if (document.body.clientHeight != 'undefined' && document.documentElement.clientHeight != 'undefined') {
        newHeight = document.body.clientHeight < document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
        newHeight = newHeight - 3;
    }


    var thispoliceNum = this.policemanNumber;
    var Level = this.Level;
    var FLowId = this.FlowId;
    var FlowImplementId = this.FlowImplementId;
    function updataLevelForm(form, v) {
        form.form.load({
            url: '../Service/FlowElementViewService.aspx?Action=GetLevelInfo&flowId=' + FLowId,
            params: { level: v },
            waitMsg: '正在读取数据...',
            waitTitle: '请稍后...',
            failure: function (form, action) {
                var reText = action.response.responseText;
                var reTextObj = Ext.util.JSON.decode(reText);
                if (eval(reTextObj.success)) {
                    form.findField('Range').setValue(reTextObj.message);
                }
            },
            success: function (form, action) {
                var reText = request.responseText;
                var reTextObj = Ext.util.JSON.decode(reText);
                if (eval(reTextObj.success)) {
                    form.findField('Range').setValue(reTextObj.message);
                }
            }
        });
    }

   var elementGrid = new FantastPlatform.UI.PadImplementGrid({
        url: '../Service/FlowElementViewService.aspx?Action=SearchImplement',
        level: 0,
        height: newHeight - 5,
        border: false
    });
    this.task = {
        run: function () {
            elementGrid.store.reload();
            uLevelInfo.load({
                url: '../Service/FlowFileViewService.aspx?Action=GetImplement',
                params: { id: FlowImplementId },
                waitMsg: '正在读取数据...',
                waitTitle: '请稍后...',
                failure: function (form, action) {
                    if (action.failureType != 'client') {
                        showErrorMessage('操作失败', action.result.message, '');
                    }
                },
                success: function (form, action) {

                }
            });
        },
        interval: 10000, //2秒刷新一次   

        scope: this
    };
    //定时执行任务    
    Ext.TaskMgr.start(this.task);
    this.ElementGrid = elementGrid;
    var uLevelInfo = new Ext.form.FormPanel({
        border: false,
        split: true,
        style: 'border:solid 1px',
        labelWidth: 70,
        height: newHeight - 5,
        labelAlign: 'right',
        bodyStyle: 'padding:5px 5px 0',
        collapsible: true,
        title: '流程基本信息',
        items: [{
            layout: 'column',
            border: false,
            labelSeparator: '：',
            items: [{
                columnWidth: 1,
                border: false,
                layout: 'form',
                items: [new Ext.form.Hidden({
                    name: 'Id'
                })]
            }, {
                columnWidth: 1,
                border: false,
                layout: 'form',
                items: [new FantastPlatform.UI.DateTimeField({
                    fieldLabel: '开始时间',
                    allowBlank: false,
                    name: 'StartTime',
                    timeFormat: 'H:i',
                    width: 180,
                    dateFormat: 'Y-m-d'
                })]
            }, {
                columnWidth: 1,
                border: false,
                layout: 'form',
                items: [new FantastPlatform.UI.DateTimeField({
                    fieldLabel: '结束时间',
                    allowBlank: false,
                    name: 'EndTime',
                    timeFormat: 'H:i',
                    width: 180,
                    dateFormat: 'Y-m-d'
                })]
            }, {
                columnWidth: 1,
                border: false,
                layout: 'form',
                items: [new Ext.form.TextField({
                    fieldLabel: '预案名称',
                    name: 'Name',
                    anchor: '90%',
                    readOnly: true
                })]
            }, {
                columnWidth: 1,
                border: false,
                layout: 'form',
                items: [new Ext.form.TextField({
                    fieldLabel: '级别',
                    name: 'Level',
                    anchor: '90%'
                })]
            }, {
                columnWidth: 1,
                border: false,
                layout: 'form',
                items: [new Ext.form.TextField({
                    fieldLabel: '状态',
                    name: 'Status',
                    allowBlank: false,
                    blankText: " 梯队数量不能为空"
                })]
            }, {
                columnWidth: 1,
                border: false,
                layout: 'form',
                items: [new Ext.form.TextField({
                    fieldLabel: '总人数',
                    name: 'TotalPerson',
                    allowBlank: false,
                    blankText: " 梯队数量不能为空"
                })]
            }, {
                columnWidth: 1,
                border: false,
                layout: 'form',
                items: [new Ext.form.TextField({
                    fieldLabel: '指挥领导',
                    name: 'Leader',
                    allowBlank: false,
                    blankText: " 指挥领导不能为空",
                    anchor: '90%'
                })]
            }, {
                columnWidth: 1,
                border: false,
                layout: 'form',
                items: [new Ext.form.TextArea({
                    fieldLabel: '要求',
                    name: 'Require',
                    allowBlank: false,
                    blankText: " 要求不能为空",
                    height: 200,
                    anchor: '90%'
                })]
            }]
        }]
    });
    this.FlowForm = uLevelInfo;
    this.items = [{
        columnWidth: .3,
        height: newHeight,
        border: false,
        items: [uLevelInfo]
    }, {
        columnWidth: .7,
        height: newHeight,
        border: false,
        items: [elementGrid]
    }];
    FantastPlatform.UI.EmergencyFlow.superclass.constructor.call(this, {
        layout: 'column',
        border: false
    });
};

Ext.extend(FantastPlatform.UI.EmergencyFlow, Ext.Panel, {
    onRender: function (ct, position) {
        var Form = this.FlowForm;
        var ImplementGrid = this.ElementGrid;
        var panel = this;
        FantastPlatform.UI.EmergencyFlow.superclass.onRender.call(this, ct, position);
        if (this.FlowImplementId && this.FlowImplementId != 0) {
            Form.load({
                url: '../Service/FlowFileViewService.aspx?Action=GetImplement',
                params: { id: this.FlowImplementId },
                waitMsg: '正在读取数据...',
                waitTitle: '请稍后...',
                failure: function (form, action) {
                    if (action.failureType != 'client') {
                        showErrorMessage('操作失败', action.result.message, '');
                    }
                },
                success: function (form, action) {

                }
            });
            ImplementGrid.store.removeAll();
            ImplementGrid.store.load({ params: { flowId: this.FlowImplementId, start: 0, limit: ImplementGrid.paperBar.getPageNumber(), dir: '', sort: ''} });
        }      
    }
});